<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <title>基本资料</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="csrf-token" content="{:token()}">
    <link rel="stylesheet" href="/static/backend/lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/backend/css/public.css" media="all">
    <style>
        .layui-form-item .layui-input-company {width: auto;padding-right: 10px;line-height: 38px;}
    </style>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <div class="layui-form layuimini-form">
            <input type="hidden" name="id" value="{$basicInfo['id']}">
            <div class="layui-form-item">
                <label class="layui-form-label required">用户名</label>
                <div class="layui-input-block">
                    <input type="text" name="" value="{$basicInfo['username']}" readonly class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">昵称</label>
                <div class="layui-input-block">
                    <input type="text" name="nickname" lay-verify="required|nickname" lay-reqtext="昵称不能为空" value="{$basicInfo['nickname']}" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">密码</label>
                <div class="layui-input-block">
                    <input type="password" name="password" lay-verify="password" value="" class="layui-input">
                    <tip>如果不修改密码就不需要填写</tip>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">角色</label>
                <div class="layui-input-block">
                    <select name="role" lay-verify="required">
                        {if ($basicInfo.admin_role_id==0) }
                        <option value="0" selected>超级管理员</option>
                        {else /}
                        <option></option>
                        {foreach $roleList as $v}
                        <option value="{$v.id}" {$v.id==$basicInfo.admin_role_id?'selected':''}>{$v.name}</option>
                        {/foreach}
                        {/if}
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="/static/backend/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="/static/backend/js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script>
    layui.use(['form','miniTab'], function () {
        var form = layui.form,
            layer = layui.layer,
            miniTab = layui.miniTab,
            $ = layui.$;

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            $.ajaxSetup({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                }
            });
            $.post('/backend/update-basic-info', data.field, function (res) {
                if (res.code == 0) {
                    // 修改成功
                    layer.msg(res.msg, {
                        icon: 1,
                        time: 1000
                    },function () {
                        // 重新加载父页面
                        location.reload();
                    })
                } else if (res.code == 302) {
                    // 错误跳转
                    location.href = '/backend/error/' + res.msg;
                } else {
                    // 修改失败
                    layer.msg(res.msg, {icon: 2});
                }
            }, 'json');
            return false;
        });

        // 自定义验证规则
        form.verify({
            nickname: function (value, item) {
                if (value.length > 20) {
                    return '昵称不能超过20个字符';
                }
            },
            password: function (value, item) {
                if (value.length>0 && (!/^\S{6,20}$/.test(value))) {
                    return '密码要在6-20位之间'
                }
            }
        })

    });
</script>
</body>
</html>